package com.taotao.web.service;


import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.taotao.common.service.ApiService;
import com.taotao.web.bean.User;

@Service
public class UserService {
	@Autowired
	private ApiService apiService;
	@Value("${SSO_TAOTAO_BASE_URL}")
	public String SSO_TAOTAO_BASE_URL;
	public static final ObjectMapper MAAPER = new ObjectMapper();

	public User queryByUserToken(String token) {
		String url = SSO_TAOTAO_BASE_URL + "/service/user/query/" + token;
		try {
			String dataJson = this.apiService.doGet(url);
			if (StringUtils.isNotEmpty(dataJson)) {
				// 不为空获得的数据反序列化
				return MAAPER.readValue(dataJson, User.class);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;

	}
}
